package com.qipay.baas.mapper;

import com.qipay.baas.model.ActionDoc;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface ActionDocMapper {
    @Delete({
        "delete from `action_doc`",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into `action_doc` (title, icon, ",
        "info, `type`, order_number)",
        "values (#{title,jdbcType=VARCHAR}, #{icon,jdbcType=VARCHAR}, ",
        "#{info,jdbcType=VARCHAR}, #{type,jdbcType=TINYINT}, #{orderNumber,jdbcType=TINYINT})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insert(ActionDoc record);

    @InsertProvider(type=ActionDocSqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insertSelective(ActionDoc record);

    @Select({
        "select",
        "id, title, icon, info, `type`, order_number",
        "from `action_doc`",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="title", property="title", jdbcType=JdbcType.VARCHAR),
        @Result(column="icon", property="icon", jdbcType=JdbcType.VARCHAR),
        @Result(column="info", property="info", jdbcType=JdbcType.VARCHAR),
        @Result(column="type", property="type", jdbcType=JdbcType.TINYINT),
        @Result(column="order_number", property="orderNumber", jdbcType=JdbcType.TINYINT)
    })
    ActionDoc selectByPrimaryKey(Integer id);

    @UpdateProvider(type=ActionDocSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(ActionDoc record);

    @Update({
        "update `action_doc`",
        "set title = #{title,jdbcType=VARCHAR},",
          "icon = #{icon,jdbcType=VARCHAR},",
          "info = #{info,jdbcType=VARCHAR},",
          "`type` = #{type,jdbcType=TINYINT},",
          "order_number = #{orderNumber,jdbcType=TINYINT}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(ActionDoc record);
}